﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using YwangHRMSys.DAL;
using YwangHRMSys.Model;


namespace YwangHRMSys.UI.SystemMgr.DepartmentMgr
{
    /// <summary>
    /// DepartmnetWindowList.xaml 的交互逻辑
    /// </summary>
    public partial class DepartmentWindowList : Window
    {
        public DepartmentWindowList()
        {
            InitializeComponent();
        }

            private void LoadData()
            {
                var dal = new DepartmentInfoDAL().ListAll();
                DataGridDepartmentList.ItemsSource = dal;

            }

            private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            LoadData();
        }

        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            DepartmentWindowEdit win=new DepartmentWindowEdit();
            win.IsInsert = true;
            if (win.ShowDialog()==true)
                {
                    LoadData();
                }
        }

        private void BtnDelete_Click(object sender, RoutedEventArgs e)
        {
            DepartmentInfoModel depart = (DepartmentInfoModel)DataGridDepartmentList.SelectedItem;
            if (depart == null)
            {
                MessageBox.Show("没有选择行!");
                return;
            }
            if (MessageBox.Show("您真的要删除" + depart.DepartmentName +"吗?", "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {

                new DepartmentInfoDAL().DeleteDepartmentInfoById(depart);

                LoadData();
            }

           
        }

        private void BtnEdit_Click(object sender, RoutedEventArgs e)
        {
            DepartmentInfoModel department = (DepartmentInfoModel)DataGridDepartmentList.SelectedItem;
            if (department == null)
            {
                MessageBox.Show("请选择行！");
                return;
            }
            DepartmentWindowEdit win = new DepartmentWindowEdit();
            win.IsInsert = false;
            win.EditGuid = department.Id;
            if (win.ShowDialog() == true)
            {
                LoadData();
            }
       

        }
    }
}
